package com.photoprint.db;

import java.util.ArrayList;
import java.util.List;
import com.photoprint.Photo;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;


public class DBMethedUtil {
	private DBHelper mDBHelper;
	private SQLiteDatabase mSQLiteDatabase;
	private DBDefine mDBDefine;
	private Context mContext;

	public DBMethedUtil(DBHelper mDBHelper,Context context){
		this.mDBHelper = mDBHelper;
		this.mContext = context;
		mSQLiteDatabase = this.mDBHelper.getWritableDatabase();
		mDBDefine = new DBDefine();		
	}
	
	public ArrayList<Photo> getShopListForNoPayNoUpdate(){
		ArrayList<Photo> al = new ArrayList<Photo>();
		StringBuffer sb = new StringBuffer();
		sb.append("select ID,THUMB_DATA,DATA,TIME_DATE,TIME_DATE,SIZE,NUMBER,IS_UPDATE,IS_PAY from shop_car");
		Cursor mCursor = mSQLiteDatabase.rawQuery(sb.toString(), null);
		if(mCursor.moveToFirst()){
			do{
				Photo p = new Photo();
				p.setId(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.ID)));
				p.setThumb_data(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.THUMB_DATA)));
				p.setImage_data(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.DATA)));
				p.setTimeDate(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.TIMEDATE)));
				p.setSize(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.SIZE)));
				p.setNumber(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.NUMBER)));
				p.setIsPay(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.IS_PAY)));
				p.setIsUpdate(mCursor.getString(mCursor.getColumnIndex(DBDefine.SHOPCAR.ISUPDATE)));
				al.add(p);
			}while(mCursor.moveToNext());
		}else{
			if(null != mCursor){
				mCursor.close();
				mCursor = null;
			}
			return null;
		}
		if(null != mCursor){
			mCursor.close();
			mCursor = null;
		}
		return al;
	}
}
